package com.bradz.mytv;

import java.math.BigDecimal;
import java.util.Random;

import org.json.JSONException;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Typeface;
import android.os.Handler;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

public class classInfoPopUp {
	private PopupWindow info_popup;
	private LinearLayout info_layout;
	private Typeface font_italic,font_bold,font_book,font_title;
	private String info_text = "myTV was created by Bradley Zimmerman, an independent developer " +
			"currently living in Boston. For questions, concerns, complaints, and compliments, " +
			"feel free to email him at mauvemoonman@gmail.com";
	private Handler myHandler;
	
	//private static final String CONFIG_ENVIRONMENT = PaymentActivity.ENVIRONMENT_NO_NETWORK;
	//private static final String CONFIG_ID = "AcoPEBD4R0XrUhnskbvhyX6JGn4U19fHct4DZd2-XJxg4kWO5sjwjfnyZVPX";
	//private static final String CONFIG_EMAIL = "mauvemoonman@gmail.com";
	
	@SuppressWarnings("deprecation")
	classInfoPopUp(final Context self, final Context baseContext, AssetManager assets, final Handler myHandler){
		this.myHandler = myHandler;
		font_italic = Typeface.createFromAsset(assets,"fonts/Neutraface2Text-BookItalic.otf");
        font_bold = Typeface.createFromAsset(assets,"fonts/Neutraface2Text-Bold.otf");
		font_book = Typeface.createFromAsset(assets,"fonts/Neutraface2Text-Book.otf");
		font_title = Typeface.createFromAsset(assets,"fonts/Neutraface2Text-Demi.otf");
		
		info_popup = new PopupWindow(self);
		info_layout = new LinearLayout(self);
		info_layout.setBackgroundColor(Color.WHITE);
		info_layout.setOrientation(1);
		info_layout.setGravity(Gravity.CENTER);
		
		LinearLayout popup_layout_0 = new LinearLayout(self);
        popup_layout_0.setGravity(Gravity.RIGHT);
        popup_layout_0.setPadding(0, 0, 20, 20);
	        TextView popUp_X = new TextView(self);
	        popUp_X.setTextSize(24);
	        popUp_X.setTextColor(self.getResources().getColor(R.color.popup_text));
	        popUp_X.setText("X");
	        popUp_X.setTypeface(font_bold);
	        popUp_X.setOnClickListener(new View.OnClickListener() {
	            public void onClick(View v) {
	            	info_popup.dismiss();
	            }
	        });
	    popup_layout_0.addView(popUp_X);
	    
	    LinearLayout popup_layout_1 = new LinearLayout(self);
        popup_layout_1.setGravity(Gravity.LEFT);
        popup_layout_1.setPadding(40, 0, 40, 20);
	        TextView popUp_title = new TextView(self);
	        popUp_title.setTextSize(24);
	        popUp_title.setGravity(Gravity.LEFT);
	        popUp_title.setTextColor( self.getResources().getColor(R.color.popup_text));
	        popUp_title.setText("Info");
	        popUp_title.setTypeface(font_italic);
        popup_layout_1.addView(popUp_title);
        
        LinearLayout popup_layout_2 = new LinearLayout(self);
        popup_layout_2.setGravity(Gravity.CENTER);
        popup_layout_2.setPadding(40, 0, 40, 20);
	        TextView popUp_text = new TextView(self);
	        popUp_text.setTextSize(14);
	        popUp_text.setTextColor( self.getResources().getColor(R.color.popup_text));
	        popUp_text.setText(info_text);
	        popUp_text.setTypeface(font_italic);
       popup_layout_2.addView(popUp_text);
       
       /*
        * 		    <Button
		        android:id="@+id/main_button_channel_settings"
		        android:layout_width="match_parent"
		        android:layout_height="wrap_content"
		        android:layout_margin="5dp"
		        android:layout_weight="0.25"
		        android:background="@drawable/selector_edges_button"
		        android:textColor="@color/button_color"
		        android:textSize="20sp"
		        android:text="@string/main_button_channel_settings" />
        */
       
       LinearLayout popup_layout_3 = new LinearLayout(self);
       popup_layout_3.setGravity(Gravity.CENTER);
       popup_layout_3.setPadding(40, 20, 40, 0);
       		Button popUp_donate_button = new Button(self);
       		//popUp_donate_button.setBackground(self.getResources().getDrawable(R.drawable.selector_edges_button));
       		popUp_donate_button.setBackgroundDrawable(self.getResources().getDrawable(R.drawable.selector_edges_button));
	        popUp_donate_button.setBackgroundColor(self.getResources().getColor(R.color.popup_text));
	        popUp_donate_button.setTextColor(self.getResources().getColor(R.color.button_color));
	        popUp_donate_button.setText("DONATE");
	        popUp_donate_button.setTypeface(font_book);
	        popUp_donate_button.setOnClickListener(new View.OnClickListener() {
	            public void onClick(View v) {
	            	myHandler.sendEmptyMessage(0);
	            }
	        });
	    popup_layout_3.addView(popUp_donate_button);
	    
	    info_layout.addView(popup_layout_0);
	    info_layout.addView(popup_layout_1);
	    info_layout.addView(popup_layout_2);
	    info_layout.addView(popup_layout_3);
	    
	    info_layout.setFocusable(true);
	    info_layout.setFocusableInTouchMode(true);
	    
	    info_popup.setContentView(info_layout);
	    info_popup.setFocusable(true);
	}

	public void attach_popup_window(ImageView info_image, final Display display){
		info_image.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("NewApi")
			public void onClick(View v) {
            	Point size = new Point();
            	try {
                    display.getSize(size);
                } catch (java.lang.NoSuchMethodError ignore) { // Older device
                	size.x = display.getWidth();
                	size.y = display.getHeight();
                }
            	info_popup.showAtLocation(info_layout, Gravity.CENTER, 0, 0);
            	info_popup.update(0, 0, size.x-(size.x/3), size.y-(2*size.y/5));
            }
        });
	}
	
	/*
    @Override
    protected void onActivityResult (int requestCode, int resultCode, Intent data) {
        if (resultCode == Activity.RESULT_OK) {
            PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
            if (confirm != null) {
                try {
                    Log.i("paymentExample", confirm.toJSONObject().toString(4));

                    // TODO: send 'confirm' to your server for verification.
                    // see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
                    // for more details.

                } catch (JSONException e) {
                    Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
                }
            }
        }
        else if (resultCode == Activity.RESULT_CANCELED) {
            Log.i("paymentExample", "The user canceled.");
        }
        else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
            Log.i("paymentExample", "An invalid payment was submitted. Please see the docs.");
        }
    }*/
}
